<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "edu_enter_gifts".
 *
 * @property int $id
 * @property string $title 礼包名称
 * @property string $poster 头部图
 * @property string $image 封面图
 * @property int $gain_id 礼包的好处
 * @property int $auth_id 礼包的权限
 * @property string $desc 礼包补充说明
 * @property string $color_start 开始颜色
 * @property string $color_end 结束颜色
 * @property int $status 1启用2禁用
 * @property int $create_time 创建时间
 * @property string $price
 * @property int $style 1是298 2是29800
 * @property string $freight 运费
 * @property string $rule 平台协议
 */
class EduEnterGifts extends \yii\db\ActiveRecord
{

    //定义场景
    const SCENARIO_UPDATE = 'update';
    const SCENARIO_UPLOAD = 'upload';
    const SCENARIO_CREATE = 'create';
    const SCENARIO_UPLOAD_POST = 'upload-post';

    public $file;

    public $files;
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'edu_enter_gifts';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['title', 'poster', 'image', 'gain_id', 'auth_id', 'color_start', 'color_end', 'create_time', 'price'], 'required'],
            [['gain_id', 'auth_id', 'status', 'create_time', 'style'], 'integer'],
            [['price', 'freight'], 'number'],
            [['rule'], 'string'],
            [['file','files'], 'file'],
            [['file', 'files'], 'safe'],
            [['title'], 'string', 'max' => 30],
            [['poster', 'image'], 'string', 'max' => 500],
            [['desc'], 'string', 'max' => 5000],
            [['color_start', 'color_end'], 'string', 'max' => 20],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '商品',
            'poster' => '海报头部',
            'image' => '封面图',
            'gain_id' => '获取',
            'auth_id' => '权限',
            'desc' => '描述',
            'color_start' => '结束颜色',
            'color_end' => '开始颜色',
            'status' => '订单状态',
            'create_time' => '创建时间',
            'price' => '单价',
            'style' => '类别',
            'freight' => '邮费',
            'rule' => '规则',
        ];
    }

    /**
     * @return array
     * 定义场景
     */
    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_UPDATE] = ['title', 'poster','image', 'gain_id', 'auth_id', 'desc', 'color_start', 'color_end', 'status', 'create_time', 'price', 'style', 'freight', 'rule'];
        $scenarios[self::SCENARIO_UPLOAD] = ['file'];
        $scenarios[self::SCENARIO_UPLOAD_POST] = ['files'];
        $scenarios[self::SCENARIO_CREATE] = ['title', 'poster','image', 'gain_id', 'auth_id', 'desc', 'color_start', 'color_end', 'status', 'create_time', 'price', 'style', 'freight', 'rule'];
        return $scenarios;
    }
}
